{php}echo "<?php\n"{/php}
namespace app\{$module}\controller;

use app\common\controller\LiteBase;
use app\common\util\Assert;
use app\common\util\DateTimeUtil;
use app\common\util\LoginManager;
use think\Input;

class {$name} extends LiteBase
{
    public function index()
    {
        return $this->fetch();
    }

    public function save()
    {
        if (IS_POST) {
            try {
                $db = \app\common\model\{$name}::instance();
                $postData = Input::post();
                $saveData = Assert::notEmpty($postData, [{volist name="fields" id="vo"}{if condition="$vo.field neq 'id' && $vo.field neq 'create_time' && $vo.field neq 'member_id'"}'{$vo.field}',{/if}{/volist}]);
                $saveData['create_time'] = DateTimeUtil::now();
                if (LoginManager::isLoginOn()) {
                    $saveData['member_id'] = LoginManager::getLoginUserId();
                } else {
                    $saveData['member_id'] = 0;
                }
                $lastId = $db->add($saveData);
                if ($lastId) {
                    return $this->jsonSuccess('提交成功');
                }
            } catch (\Exception $ex) {
                return $this->jsonFail($ex->getMessage());
            }
        }
        return $this->jsonFail('系统忙');
    }
    public function saveResult()
    {
        return $this->fetch();
    }
    public function workResult()
    {
        $id = Input::get('id') + 0;
        return $this->fetch('failResult');
        //$this->assign('op', 1);
        //$this->assign('m', ValueBag::wrap(\app\common\model\Appointment::instance()->find($id)));
        //return $this->saveResult();
    }
}